package 多线程.交替输出;

import java.util.HashMap;
import java.util.WeakHashMap;
import java.util.concurrent.Callable;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.locks.LockSupport;

/**
 * @author : K k
 * @date : 11:22 2020/8/11
 * 最优解
 */
public class Ans1LockSupport {

    static Thread t1=null,t2=null;

    public static void main(String[] args) {
        char[] a1="1234567".toCharArray();
        char[] a2="ABCDEFG".toCharArray();

        t1=new Thread(()->{
            for (char c : a1){
                System.out.println(c);
                LockSupport.unpark(t2);
                LockSupport.park();
            }
        });

        t2=new Thread(()->{
            for (char c : a2){
                LockSupport.park();
                System.out.println(c);
                LockSupport.unpark(t1);
            }
        });

        t1.start();
        t2.start();
    }
}
